package com.hzjy.manage.controller;

import java.util.List;

import com.hzjy.api.beans.SysCommonProblem;
import com.hzjy.api.service.impl.SysCommonProblemServiceImpl;
import com.hzjy.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hzjy.common.core.controller.BaseController;
import com.hzjy.common.core.domain.AjaxResult;
import com.hzjy.common.core.page.TableDataInfo;

/**
 * 常见问题Controller
 * 
 * @author hzjy
 * @date 2020-09-05
 */
@RestController
@RequestMapping("/manage/problem")
public class CommonProblemController extends BaseController
{
    @Autowired
    private SysCommonProblemServiceImpl sysCommonProblemService;

    /**
     * 查询常见问题列表
     */
    @PreAuthorize("@ss.hasPermi('system:problem:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCommonProblem sysCommonProblem)
    {
        startPage();
        List<SysCommonProblem> list = sysCommonProblemService.selectSysCommonProblemList(sysCommonProblem);
        return getDataTable(list);
    }

    /**
     * 导出常见问题列表
     */
    @PreAuthorize("@ss.hasPermi('system:problem:export')")
    @GetMapping("/export")
    public AjaxResult export(SysCommonProblem sysCommonProblem)
    {
        List<SysCommonProblem> list = sysCommonProblemService.selectSysCommonProblemList(sysCommonProblem);
        ExcelUtil<SysCommonProblem> util = new ExcelUtil<SysCommonProblem>(SysCommonProblem.class);
        return util.exportExcel(list, "problem");
    }

    /**
     * 获取常见问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:problem:query')")
    @GetMapping("/selectOne")
    public AjaxResult getInfo( Long id)
    {
        return AjaxResult.success(sysCommonProblemService.selectSysCommonProblemById(id));
    }

    /**
     * 新增常见问题
     */
    @PreAuthorize("@ss.hasPermi('system:problem:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysCommonProblem sysCommonProblem)
    {
        return toAjax(sysCommonProblemService.insertSysCommonProblem(sysCommonProblem));
    }

    /**
     * 修改常见问题
     */
    @PreAuthorize("@ss.hasPermi('system:problem:edit')")
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody SysCommonProblem sysCommonProblem)
    {
        sysCommonProblemService.updateSysCommonProblem(sysCommonProblem);
        return AjaxResult.success();
    }

    /**
     * 删除常见问题
     */
    @PreAuthorize("@ss.hasPermi('system:problem:remove')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysCommonProblemService.deleteSysCommonProblemByIds(ids));
    }

    /**
     * 删除常见问题
     */
    @PreAuthorize("@ss.hasPermi('system:problem:remove')")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody SysCommonProblem sysCommonProblem)
    {
        return toAjax(sysCommonProblemService.deleteSysCommonProblemById(sysCommonProblem.getId()));
    }
}
